package com.haiyou.dc.ehcache.service.impl;

import com.haiyou.common.base.AbstractBaseService;
import com.haiyou.dc.ehcache.entity.Movie;
import com.haiyou.dc.ehcache.mapper.MovieMapper;
import com.haiyou.dc.ehcache.service.MovieService;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author root
 * @date 2020-02-24 20:03:25
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class MovieServiceImpl extends AbstractBaseService<MovieMapper, Movie> implements MovieService {

    @Cacheable(value = "movie")
    @Override
    public Movie movieByCache(Integer id) {
        return this.selectByPrimaryKey(id);
    }

    @CacheEvict(value = "movie", allEntries = true)
    @Override
    public void addMovieCleanCache(Movie movie) {
        this.insert(movie);
    }
}